package sel.me.spring.boot159.web.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import sel.me.spring.boot159.web.dao.PersonMapper;
import sel.me.spring.boot159.web.entity.PersonDO;

@Service
public class TestPersonServiceOut {

    @Autowired
    private PersonMapper personMapper;

    @Autowired
    private TransactionTemplate transactionTemplate;

    @Autowired
    private TestPersonServiceInner testPersonServiceInner;

    public void out(){
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                testPersonServiceInner.inner();

                PersonDO personDO = new PersonDO();
                personDO.setId(101);
                personMapper.insert(personDO);

                throw new RuntimeException();
            }
        });
    }

}
